package oneroom.admin.oneroom;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import oneroom.comm.IbatisLoader;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapExecutor;

public class roomDao {
	private IbatisLoader 	iBatis;
	private SqlMapClient 	sqlMapper;
	
	public roomDao(){
		this.sqlMapper = iBatis.setConfig();
	}
	/**
	 * 리스트
	 * @return
	 */
	public List getList(String searchGubn, String searchValue, int selectPage, int pageSize){
		List returnValue = new ArrayList();
		if (selectPage == 0) selectPage = 1;
		if (pageSize == 0) pageSize = 10;
		int startPos = ((selectPage-1)*pageSize);
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("searchGubn", searchGubn);
		param.put("searchValue", searchValue);
		param.put("startPos", startPos);
		param.put("pageSize", pageSize);
		try{
			returnValue = (List)sqlMapper.queryForList("room.roomlist",param);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	/**
	 * my리스트
	 * @return
	 */
	public List getMyList(String searchGubn, String searchValue, int selectPage, int pageSize, String id){
		List returnValue = new ArrayList();
		if (selectPage == 0) selectPage = 1;
		if (pageSize == 0) pageSize = 10;
		int startPos = ((selectPage-1)*pageSize);
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("searchGubn", searchGubn);
		param.put("searchValue", searchValue);
		param.put("startPos", startPos);
		param.put("pageSize", pageSize);
		param.put("id", id);
		try{
			returnValue = (List)sqlMapper.queryForList("room.roommylist",param);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}	
	/**
	 * my리스트 갯수
	 * @return
	 */
	public int getMyCount(String id){
		int returnValue = 0;
		try{
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("id", id);
			returnValue = ((Integer)sqlMapper.queryForObject("room.roommycount",param)).intValue();	
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}	
	/**
	 * 게시물 전체 갯수
	 * @return
	 */
	public int getCount(String searchGubn, String searchValue){
		int returnValue = 0;
		try{
			Map<String, Object> param = new HashMap<String, Object>();			
			param.put("searchGubn", searchGubn);
			param.put("searchValue", searchValue);
			returnValue = ((Integer)sqlMapper.queryForObject("room.roomcount",param)).intValue();	
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	/**
	 * 상세보기
	 * @param oneroom_seq
	 * @return
	 */
	public roomModel getView(String oneroom_seq){
		roomModel returnValue = new roomModel();
		try{
			returnValue = (roomModel)sqlMapper.queryForObject("room.roomview", oneroom_seq);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	/**
	 * 수정
	 * @param roommodel
	 * @return
	 */
	public boolean getUpdate(roomModel roommodel){
		boolean returnValue = false;
		try{
			if(sqlMapper.update("room.roomupdate", roommodel) > 0){
				returnValue = true;
			}else{
				returnValue = false;
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	/**
	 * 날짜수정
	 * @param roommodel
	 * @return
	 */
	public boolean getDateupdate(String oneroom_seq){
		boolean returnValue = false;
		try{
			if(sqlMapper.update("room.roomdateupdate", oneroom_seq) > 0){
				returnValue = true;
			}else{
				returnValue = false;
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}	

	/**
	 * 날짜수정 하루 초과 조회
	 * @param roommodel
	 * @return
	 */
	public int getDateupdateHistory(String id){
		int returnValue = 0;		
		try{
			returnValue = ((Integer)sqlMapper.queryForObject("room.history_cnt",id)).intValue();	
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}	
	/**
	 * 날짜수정 이력 저장
	 * @param roommodel
	 * @return
	 */	
	public void getHitHistory(String id){
		try{
			sqlMapper.update("room.history_hit", id);
		}catch (Exception e) {
			// TODO: handle exception
		}
	}
	/**
	 * 허위매물 초기화
	 * @param roommodel
	 * @return
	 */
	public boolean getResetupdate(String oneroom_seq){
		boolean returnValue = false;
		try{
			if(sqlMapper.delete("room.roomresetupdate", oneroom_seq) > 0){
				returnValue = true;
			}else{
				returnValue = false;
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}		
	/**
	 * 등록
	 * @param roommodel
	 * @return
	 */
	public boolean getInsert(roomModel roommodel){
		boolean returnValue = true;
		try{
			sqlMapper.insert("room.roominsert", roommodel);
		}catch (Exception e) {
			// TODO: handle exception
			returnValue = false;
		}
		return returnValue;
	}
	
	
	/**
	 * 삭제
	 * @param oneroom_seq
	 * @return
	 */
	public boolean getDelete(String oneroom_seq){
		boolean returnValue = false;
		try{
			if(sqlMapper.delete("room.roomdelete", oneroom_seq) > 0){
				returnValue = true;
			}else{
				returnValue = false;
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	
	/**
	 * 게시물 전체 갯수
	 * @return
	 */
	public HashMap getSelectCnt(HashMap paramMap){
		HashMap	returnValue	= new HashMap();		
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("id",paramMap.get("id"));
		try{
			returnValue = (HashMap) sqlMapper.queryForObject("room.select_cnt",param);	
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}	
	
	
	/**
	 * 신고등록
	 * @param roommodel
	 * @return
	 */
	public boolean getReportInsert(reportModel reportmodel){
		boolean returnValue = true;
		try{
			if(((Integer)sqlMapper.queryForObject("room.report_check",reportmodel)).intValue() <= 0){
				sqlMapper.insert("room.report_insert", reportmodel);
			}else{
				returnValue = false;
			}			
		}catch (Exception e) {
			// TODO: handle exception
			returnValue = false;
		}
		return returnValue;
	}	

	/**
	 * 신고등록 전체 갯수
	 * @return
	 */
	public HashMap getReportCnt(String oneroom_seq){
		HashMap	returnValue	= new HashMap();		
		try{
			returnValue = (HashMap)sqlMapper.queryForObject("room.report_cnt",oneroom_seq);	
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}		
	/**
	 * max 카운트
	 * @return
	 */
	public int getMaxCnt(String id){
		int returnValue = 0;		
		try{
			returnValue = ((Integer)sqlMapper.queryForObject("room.roommaxcnt",id)).intValue();	
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}	
}
